package com.ruoyi.web.controller.customer;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.quartz.task.Atask;
import com.ruoyi.quartz.task.FileSaveDownDto;
import com.ruoyi.system.domain.UserTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserOssTask;
import com.ruoyi.system.service.IUserOssTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * OSS存储Controller
 * 
 * @author ruoyi
 * @date 2024-12-09
 */
@RestController
@RequestMapping("/system/oss_task")
@Api(tags = "OSS控制器")
public class UserOssTaskController extends BaseController
{
    @Autowired
    private IUserOssTaskService userOssTaskService;
    @Autowired
    private Atask atask;
    /**
     * 查询OSS存储列表
     */
    @PreAuthorize("@ss.hasPermi('system:oss_task:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserOssTask userOssTask)
    {
        startPage();
        List<UserOssTask> list = userOssTaskService.selectUserOssTaskList(userOssTask);
        return getDataTable(list);
    }

    /**
     * 导出OSS存储列表
     */
    @PreAuthorize("@ss.hasPermi('system:oss_task:export')")
    @Log(title = "OSS存储", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserOssTask userOssTask)
    {
        List<UserOssTask> list = userOssTaskService.selectUserOssTaskList(userOssTask);
        ExcelUtil<UserOssTask> util = new ExcelUtil<UserOssTask>(UserOssTask.class);
        util.exportExcel(response, list, "OSS存储数据");
    }

    /**
     * 获取OSS存储详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:oss_task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userOssTaskService.selectUserOssTaskById(id));
    }

    /**
     * 新增OSS存储
     */
    @PreAuthorize("@ss.hasPermi('system:oss_task:add')")
    @Log(title = "OSS存储", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserOssTask userOssTask)
    {
        return toAjax(userOssTaskService.insertUserOssTask(userOssTask));
    }

    /**
     * 修改OSS存储
     */
    @PreAuthorize("@ss.hasPermi('system:oss_task:edit')")
    @Log(title = "OSS存储", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserOssTask userOssTask)
    {
        return toAjax(userOssTaskService.updateUserOssTask(userOssTask));
    }

    /**
     * 删除OSS存储
     */
    @PreAuthorize("@ss.hasPermi('system:oss_task:remove')")
    @Log(title = "OSS存储", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userOssTaskService.deleteUserOssTaskByIds(ids));
    }
    @PostMapping("ts")
    @ApiOperation("测试")
    public AjaxResult ts(String s,String sid) throws Exception {
        UserTask userTask = new UserTask();
        userTask.setName("2123232.png");
        userTask.setVideoUrl("https://qny.sunne.xyz/AiArt/sys/model/541cf4daa2d24964ad35dff7d5003b55_0.png");
        userTask.setId(Long.parseLong("1"));
        userTask.setCreateBy("1");
//        RyTask ryTask = new RyTask();
//        ryTask.AddOSS(userTask);
        FileSaveDownDto dto = new FileSaveDownDto();
        dto.setSavepath("admin/20241209/"+s+".png");
        dto.setDownpath("https://qny.sunne.xyz/AiArt/sys/model/541cf4daa2d24964ad35dff7d5003b55_0.png");
        String asyncid = "84972946928149821";
        atask.Fcli(dto,sid);
        return AjaxResult.success();
    }
}
